package com.ztjava.remind.controller;

import java.util.List;

import com.jfinal.aop.Duang;
import com.ztjava.core.Constant;
import com.ztjava.core.annotation.ControllerClass;
import com.ztjava.core.base.BaseController;
import com.ztjava.core.bean.remind.RemindMsgBean;
import com.ztjava.core.client.member.MobileClient;
import com.ztjava.core.tool.ViewTool;
import com.ztjava.ext.auth.annotation.UserController;
import com.ztjava.ext.auth.annotation.UserMethod;
import com.ztjava.ext.auth.bean.AuthSession;
import com.ztjava.remind.service.RemindService;

@UserController(portal=Constant.P_MEMBER)
@ControllerClass(client=MobileClient.class,path="/remind")
public class RemindMobileController extends BaseController{
	private static RemindService remindService = Duang.duang(RemindService.class);
	@UserMethod
	public void index(){
		render("index.html");
	}
	@UserMethod
	public void ajaxLoadMsg(){
		String plugin = getPara("plugin","COMMON");
		String component = getPara("component",plugin);
		AuthSession authSession = getAttr(Constant.AUTHSESSION);
		List<RemindMsgBean> infoList = remindService.getMsgList(plugin,component, authSession.getId(), getParaToInt(client.getPageNumber(),1), getParaToInt(client.getPageSize(),20));
		for(int i=0;i<infoList.size();i++){
			infoList.get(i).setCreate_time_change(ViewTool.dateChange(infoList.get(i).getCreate_time()));
		}
		setAttr(Constant.RESULT, Constant.SUCCESS);
		setAttr("infoList", infoList);
		renderJson(new String[]{Constant.RESULT,"infoList"});
	}


	@UserMethod
	public void deleteMsg(){
		String plugin = getPara("plugin","COMMON");
		String id = getPara("id");
		AuthSession authSession = getAttr(Constant.AUTHSESSION);
		remindService.deleteMsg(plugin, authSession.getId(), id);
		renderSuccess();
	}
	@UserMethod
	public void clearAllMsg(){
		String plugin = getPara("plugin","COMMON");
		AuthSession authSession = getAttr(Constant.AUTHSESSION);
		remindService.deleteAll(plugin, authSession.getId());
		renderSuccess();
	}
}
